﻿using Microsoft.Extensions.Configuration;
using MiniFox.Configurations;

namespace MiniFox.Components.Configurations
{
    /// <summary>
    /// 组件配置
    /// </summary>
    public sealed class ComponentConfig : IComponentConfig
    {

        const string CONTRACT_TYPE = "contractType";
        const string DEFAULT_PROVIDER = "defaultProvider";
        const string BUILDER_TYPE = "builderType";
        const string LEFT_STYPE = "lifeStyle";
        const string PROVIDERS = "providers";

        /// <summary>
        /// 
        /// </summary>
        public ComponentConfig()
        {
            this.LifeStyle = ComponentLifeStyleType.Transient;
        }
        /// <summary>
        /// 契约类型(接口或抽象类)完全限定名(FullName)
        /// </summary>
        [ConfigurationKeyName(CONTRACT_TYPE)]
        public string ContractType
        {
            get;
            set;
        }
        /// <summary>
        /// 默认组件提供者名称，该名称用于在提供者集合中查找提供者并创建实现类型
        /// </summary>
        [ConfigurationKeyName(DEFAULT_PROVIDER)]
        public string DefaultProvider
        {
            get;
            set;
        }
        /// <summary>
        /// 组件生成器完全限定名(FullName)
        /// </summary>
        [ConfigurationKeyName(BUILDER_TYPE)]
        public string BuilderType
        {
            get;
            set;
        }
        /// <summary>
        /// 组件生存期策略
        /// </summary>
        [ConfigurationKeyName(LEFT_STYPE)]
        public ComponentLifeStyleType LifeStyle
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        [ConfigurationKeyName(PROVIDERS)]
        public ProviderSettingsCollection Providers
        {
            get;
            set;
        } = new();

        ///// <summary>
        ///// 
        ///// </summary>
        //public ComponentProviderCollection Providers
        //{
        //    get
        //    {
        //        var providers = new ComponentProviderCollection();
        //        foreach (ProviderSettings setting in this.ProviderSettings)
        //        {
        //            providers.Add(new ComponentProvider(setting.Name, setting.Type));
        //        }
        //        return providers;
        //    }
        //}
    }
}
